﻿function ServerCallbackValidator_DoCallback(eventTarget, eventArgument)
{
    /*
    function encode(parameter)
    {
        if (encodeURIComponent) {
            return encodeURIComponent(parameter);
        }
        else {
            return escape(parameter);
        }
    }
    */
    
    var result = false;
    var completed = false;
    
    var postData = __theFormPostData +
                "__CALLBACKID=" + WebForm_EncodeCallback(eventTarget) +
                "&__CALLBACKPARAM=" + WebForm_EncodeCallback(eventArgument);
    if (theForm["__EVENTVALIDATION"]) {
        postData += "&__EVENTVALIDATION=" + WebForm_EncodeCallback(theForm["__EVENTVALIDATION"].value);
    }
    
    //var postData = "__EVENTTARGET=&__EVENTARGUMENT=__EVENTVALIDATION=&__CALLBACKID=" + WebForm_EncodeCallback(eventTarget) +
    //            "&__CALLBACKPARAM=" + WebForm_EncodeCallback(eventArgument);
   
    //if(__theFormPostData != null)
    //    postData = __theFormPostData + postData;
                 
        new Ajax.Request(theForm.action,
        {
            method: 'post',
            parameters: postData,
            asynchronous: false,
            
            onSuccess: function(transport)
            {
                var data = null;
                var response = transport.responseText;     

                var trueI = response.indexOf('true');
                var falseI = response.indexOf('false');;                  
                
                if(trueI != -1 || falseI != -1)
                {
                    var startIndex = 0;
                    if(trueI != -1)
                        startIndex = trueI;
                    else
                        startIndex = falseI;
                        
                    response = response.substring(startIndex);

                    var sPos = response.indexOf('|');
                    if(sPos != -1)
                    {
                        data = response.split("|");
                        result = data;
                    }
                    else
                    {
                        if(response == "true")
                            result = true;
                        else if(response == "false")
                           result = false;
                        else   
                            result = null;                           
                    }
                }
                else
                {
                    result = null;
                }
            }.bind(this),
            onFailure: function(transport)
            {
                result = null;
            }.bind(this),
            onComplete: function()
            {
                completed = true;
            }.bind(this)
        });
        
    return result;
}